﻿using System;
using System.ComponentModel.Composition;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using VisualWip.TFS2010Common;

namespace VisualWip.TFS2010PersistanceProvider
{
    [Export(typeof(TFSPropertyServiceHelper))]
    public class TFSPropertyServiceHelper
    {
        public const string VisualWipSettingsMoniker = "VisualWIP_Settings_";
        public const string WildCard = "*";

        public ArtifactSpec ArtifactSpec
        {
            get { return new ArtifactSpec(ArtifactKinds.Generic, VisualWipSettingsMoniker, 0); }
        }

        public IPropertyService GetPropertyService(TfsConnection connection)
        {
            var ps = connection.TeamProjectCollection.GetService<IPropertyService>();

            if (ps == null)
            {
                throw new NotSupportedException(
                    String.Format("The IPropertyService is not supported or not avalible for Team Collectiobn {0}",
                                  connection.TeamProjectCollection.Name));
            }
            return ps;
        }

        public ArtifactPropertyValue[] GetAllProperties(TfsConnection connection)
        {
            return GetPropertyService(connection).GetProperties(ArtifactSpec, new[] {WildCard});
        }
    }
}